#include "f4xx_LCD_Middle.h"

void LCD_Init(void)
{
	SSD1289_Init();
	return;
}

void LCD_WriteReg(UIN16 Reg_Add, UIN16 Reg_Value)
{
	SSD1289_WriteReg(Reg_Add, Reg_Value);
	return;
}

void LCD_WritePixel(UIN16 Pix_Value)
{
	SSD1289_WritePixel(Pix_Value);
	return;
}

void LCD_SetWindow(struct LCD_Coord * Pos)
{
	SSD1289_SetWindow(Pos);
	return;
}

void LCD_CloseWindow(void)
{
	SSD1289_CloseWindow();
	return;
}

void LCD_Clear(UIN16 Color, struct LCD_Coord * Pos)
{

	LCD_SetWindow(Pos);

	*Write_Reg = 0x0022;

	UIN32 index = ZERO_32;

	for(index = ZERO_32; index < (Pos->Width)*(Pos->Height); index++)
	{
		LCD_WritePixel(Color);
	}


	*Write_Reg = 0x0022;

	LCD_CloseWindow();

	return;
}

void LCD_Test(void)
{
	struct LCD_Coord Pos;
	struct LCD_Letter_64 Letter;

	Pos.X_Add = ((UIN16) 0u);
	Pos.Y_Add = ((UIN16) 0u);
	Pos.Height = ((UIN16) 320u);
	Pos.Width = ((UIN16) 240u);

	Letter.Height = 8u;
	Letter.LetterID = Nu_0;
	Letter.Scale = 1u;
	Letter.Width = 8u;
	Letter.X_Add = 100u;
	Letter.Y_Add = 150u;
	Letter.Colour = BLACK;

	LCD_Init();

	while(1)
	{
	Delay_ms(2000);
	LCD_Clear(WHITE,&Pos);
	LCD_PrintLetter(&Letter);


		if(Letter.LetterID == Nu_9)
		{
			Letter.LetterID = Nu_0;
		}
		else
		{
			Letter.LetterID++;
		}
	}
	return;
}

inline void LCD_SetX(UIN16 X_Coord)
{
	SSD1289_WriteReg(X_Address, X_Coord);
	*Write_Reg = 0x0022;
	return;
}

inline void LCD_SetY(UIN16 Y_Coord)
{
	SSD1289_WriteReg(Y_Address, Y_Coord);
	*Write_Reg = 0x0022;
	return;
}

inline void LCD_Mask(UIN16 Mask1, UIN16 Mask2)
{
	SSD1289_WriteReg(RAM_Data_Mask_1, Mask1);
	SSD1289_WriteReg(RAM_Data_Mask_2, Mask2);
	*Write_Reg = 0x0022;
	return;
}
